package dk.flashnotes.fff.exampleMain {
	import org.osflash.thunderbolt.Logger;	
	
	import dk.flashnotes.fff.tree.TreeNode;	
	import dk.flashnotes.fff.exampleMain.parts.BasicTextPart;	
	import dk.flashnotes.fff.exampleMain.pages.BasicPage;	
	import dk.flashnotes.fff.FFFBaseEvent;	
	import dk.flashnotes.fff.FFFBase;	
	
	import flash.display.StageScaleMode;	
	import flash.display.StageAlign;	
	import flash.display.Sprite;
	
	/**
	 * @author jk
	 */
	public class SiteRoot_ExampleMain extends Sprite {
		private var _oFFF : FFFBase;		private var _sMainXMLURL : String = "maindata.xml";
		private var _sprMainCont : Sprite;

		public function SiteRoot_ExampleMain() {
			mainSetup();
		}
		
		private function mainSetup() : void {
			
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			setupFFF();
		}
		
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		// setup FFF
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		
		private function setupFFF() : void {
			
			// setup main container for the created pages
			_sprMainCont = new Sprite();
			addChild(_sprMainCont);
			
			// get refrence to the fff-instance
			_oFFF = FFFBase.get_oInstance();
			
			// setup EventListeners for initiation process
			_oFFF.addEventListener(FFFBaseEvent.etTREE_CREATED, onTreeCreated, false, 0, true);
			_oFFF.addEventListener(FFFBaseEvent.etDATA_LOADED, onMainDataLoaded, false, 0, true);
			
			// register APage and APart classes. This is nessecary when using autogeneration from xml.
			// All the registred classe must extend APage and APart.
			_oFFF.register_cAPageTypes(BasicPage);
			_oFFF.register_cAPartTypes(BasicTextPart);
			
			// enables helpers
			_oFFF.bHelpersEnabled=true; 
			
			// load and init FFF
			_oFFF.loadAndInitFFFTree(_sprMainCont, true, _sMainXMLURL);
			
		}

		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		// FFFBase events
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		
		private function onTreeCreated(event : FFFBaseEvent) : void {
			
			// start the tree controller
			_oFFF.startTreeControl();
		}

		private function onMainDataLoaded(event : FFFBaseEvent) : void {
		}
	}
}
